<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>

</head>

<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left" onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id='title_head'></div>
    </header>
    <div class="aui-bar-nav-d"></div>

</body>

<div id="list">
</div>
<script type='text/template' id='template'>
           <ul class="news">
            {{~it :value:index}}
              {{? value.icon==false}}
            <li tapmode onclick="news_detail({{=value.id}})">
              <dl>
                  <dt>{{=value.title}}</dt>
                  <dd>{{=value.description}}</dd>
              </dl>
              <div class="news-r">
                  <!-- <img src="image/news.jpg"> -->
                  <p>{{=value.update_time}}</p>
              </div>
            </li>
            {{??}}
            <li tapmode onclick="news_detail({{=value.id}})">
              <dl>
                  <dt>{{=value.title}}</dt>
                  <dd>{{=value.description}}</dd>
              </dl>
              <div class="news-r">
                {{? value.icon === false}}
0
                  {{??}}
                  <img src="http://www.big-wealth.com{{=value.icon}}">

                  {{?}}
                  <p>{{=value.update_time}}</p>
              </div>
            </li>
            {{?}}
            {{~}}
        </ul>
</script>
<script type="text/javascript">
var id = "";

    apiready = function() {
        var title = api.pageParam.title;
        $("#title_head").text(title);

        id = api.pageParam.id;
        fnGetNewData();
        down_refresh();
        addObserver();

    };
//详情页面
    function news_detail(n) {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }

        // alert(n);
        api.openWin({
            name: 'news_details',
            url: './news_details.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            pageParam: {
                id: n
            }
        });
    };


    //数据请求
    function fnGetNewData(n) {

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });

        if (n) {
            page += 1;
        } else {
            page = 1;
        }
        api.ajax({
            url: webAddress + '/index.php?ctl=app_article&act=article_list',
            method: 'post',
            data: {
                values: {
                    cate_id: id,
                    page: page
                },
            }
        }, function(ret, err) {
            if (ret) {
                var data = ret.list;
                upDataNew(data, page);
                api.refreshHeaderLoadDone();
                api.hideProgress();
            }
        });
    }

    function upDataNew(data, n) {
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');

        if (n == 1) {
            $api.html(list, html);
        } else {
            if (data == '') {

                api.toast({
                    msg: '没有更多了',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }

            $api.append(list, html);
        }

        api.parseTapmode();
    }

    //上拉刷新监听
    function addObserver() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err) {
            fnGetNewData(true);
        });
    }


    // 下拉刷新
    function down_refresh() {

        api.setRefreshHeaderInfo({
            visible: true,
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err) {
            fnGetNewData();
        });
    }




    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
